﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

using Weazel.Badger.Vhdl.Types;

namespace Weazel.Badger.Vhdl.Operators.Binary
{
  public class LessThanOrEqual : BinaryFunction
  {
    private static BinaryTypeMap[] typeMaps = new BinaryTypeMap[]
      {
        new BinaryTypeMap(Types.Types.Boolean, Types.Types.Boolean, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Character, Types.Types.Character, Types.Types.Boolean, true),        

        new BinaryTypeMap(Types.Types.Unsigned, Types.Types.Unsigned, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Unsigned, Types.Types.Signed, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Signed, Types.Types.Signed, Types.Types.Boolean, true),
        
        new BinaryTypeMap(Types.Types.Unsigned, Types.Types.Integer, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Integer, Types.Types.Unsigned, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Signed, Types.Types.Unsigned, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Signed, Types.Types.Integer, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Integer, Types.Types.Signed, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.StdLogic, Types.Types.StdLogic, Types.Types.Boolean, true)
      };

    private static BinaryTypeMap[] signedTypeMaps = new BinaryTypeMap[]
      {
        new BinaryTypeMap(Types.Types.Boolean, Types.Types.Boolean, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Character, Types.Types.Character, Types.Types.Boolean, true),        

        new BinaryTypeMap(Types.Types.Unsigned, Types.Types.Unsigned, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Unsigned, Types.Types.Signed, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Signed, Types.Types.Signed, Types.Types.Boolean, true),
        
        new BinaryTypeMap(Types.Types.Unsigned, Types.Types.Integer, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Integer, Types.Types.Unsigned, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Signed, Types.Types.Unsigned, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Signed, Types.Types.Integer, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.Integer, Types.Types.Signed, Types.Types.Boolean, true),
        new BinaryTypeMap(Types.Types.StdLogic, Types.Types.StdLogic, Types.Types.Boolean, true)
      };

    public override BinaryTypeMap[] SignedTypeMaps
    {
      get
      {
        return signedTypeMaps;
      }
    }

    public override BinaryTypeMap[] UnsignedTypeMaps
    {
      get
      {
        return typeMaps;
      }
    }

    public LessThanOrEqual()
    {
    }

    public override string ToString(string left, string right, int width)
    {
      return string.Format("{0} <= {1}", left, right);
    }
  }
}
